<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://mars3d.cn " />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />

    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico" />
    <title>SatelliteSensor 卫星视锥体 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <!--第三方lib-->
    <script
      type="text/javascript"
      src="../lib/include-lib.js"
      libpath="../lib/"
      include="jquery,font-awesome,bootstrap,bootstrap-checkbox,bootstrap-slider,layer,haoutil,turf,mars3d,mars3d-space"
    ></script>

    <link href="css/style.css" rel="stylesheet" />
  </head>

  <body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="mars3dContainer" class="mars3d-container"></div>

    <!-- 面板 -->
    <div class="infoview">
      <input type="button" class="btn btn-primary" value="定位至卫星" onclick="locate()" />

      <a href="editor.html#f60_space_satelliteSensor_multi" target="_blank" class="btn btn-link">双椎体示例</a>

      <table class="mars-table">
        <tr>
          <td>位置</td>
          <td colspan="2">
            经度
            <input id="model_x" type="number" step="0.000001" value="117.169969" style="width: 90px" />
            纬度
            <input id="model_y" type="number" step="0.000001" value="31.840886" style="width: 90px" />
            高度
            <input id="model_z" type="number" step="0.1" value="900000" style="width: 90px" />
          </td>
        </tr>

        <tr>
          <td class="nametd">轨迹方向（heading）</td>
          <td>
            <input id="model_heading" title="方向heading" />
          </td>
          <td>
            <input id="model_heading_2" readonly="readonly" type="number" min="0" max="360" step="1" value="0" title="方向heading" />
          </td>
        </tr>
        <tr>
          <td class="nametd">前后侧摆（pitch）</td>
          <td>
            <input id="model_pitch" title="前后侧摆pitch" />
          </td>
          <td>
            <input id="model_pitch_2" readonly="readonly" type="number" min="-180" max="180" step="1" value="0" title="前后侧摆pitch" />
          </td>
        </tr>
        <tr>
          <td class="nametd">左右侧摆（roll）</td>
          <td>
            <input id="model_roll" title="左右侧摆roll" />
          </td>
          <td>
            <input id="model_roll_2" readonly="readonly" type="number" min="-180" max="180" step="1" value="0" title="左右侧摆roll" />
          </td>
        </tr>

        <tr>
          <td class="nametd">参考系轴</td>
          <td>
            <div class="checkbox checkbox-primary checkbox-inline">
              <input id="chkShowModelMatrix" class="styled" type="checkbox" checked />
              <label for="chkShowModelMatrix"> 显示/隐藏 </label>
            </div>
          </td>
          <td><input id="modelMatrixLength" type="number" min="1" max="10000" step="1" value="30" />(轴长度)</td>
        </tr>

        <tr>
          <td class="nametd">视锥体状态</td>
          <td>
            <div class="checkbox checkbox-primary checkbox-inline">
              <input id="chkShowCone" class="styled" type="checkbox" checked />
              <label for="chkShowCone"> 显示/隐藏 </label>
            </div>
          </td>
          <td>
            <div class="checkbox checkbox-primary checkbox-inline coneEntityAttr">
              <input id="chkUnderground" class="styled" type="checkbox" />
              <label for="chkUnderground"> 求交地球 </label>
            </div>
          </td>
        </tr>
        <tr class="coneEntityAttr">
          <td class="nametd">类型</td>
          <td colspan="2">
            <div class="radio radio-info radio-inline">
              <input type="radio" id="shadingMaterials1" name="shadingMaterials" value="1" />
              <label for="shadingMaterials1">圆锥体</label>
            </div>
            <div class="radio radio-info radio-inline">
              <input type="radio" id="shadingMaterials2" name="shadingMaterials" value="2" checked="checked" />
              <label for="shadingMaterials2">四棱锥体</label>
            </div>
          </td>
        </tr>
        <tr class="coneEntityAttr">
          <td class="nametd">夹角1(半场角)</td>
          <td>
            <input id="model_angle1" />
          </td>
          <td>
            <input id="model_angle1_2" readonly="readonly" type="number" min="0" max="89" step="0.001" value="5" />
          </td>
        </tr>
        <tr id="tr_angle2" class="coneEntityAttr">
          <td class="nametd">夹角2(半场角)</td>
          <td>
            <input id="model_angle2" />
          </td>
          <td>
            <input id="model_angle2_2" readonly="readonly" type="number" min="0" max="89" step="0.001" value="10" />
          </td>
        </tr>

        <tr class="coneEntityAttr">
          <td class="nametd">地面成像区域</td>
          <td colspan="2">
            <button id="btnGetRegion" class="btn btn-primary">获取区域边界值</button>
            <button id="btnGetCenter" class="btn btn-primary">获取中心点坐标</button>
            <button id="btnRemoveAll" class="btn btn-primary">清除</button>
          </td>
        </tr>
      </table>
    </div>

    <script src="./js/common.js"></script>
    <script type="text/javascript">
      "use script"; //开发环境建议开启严格模式

      var map;

      var satelliteSensor;
      var modelGraphic;

      var reverse = true; //z轴方向，true朝向空中，false朝向地心
      var converter = Cesium.Transforms.eastNorthUpToFixedFrame;
      // var converter = Cesium.Transforms.localFrameToFixedFrameGenerator('east', 'south')

      function initMap(options) {
        //合并属性参数，可覆盖config.json中的对应配置
        var mapOptions = mars3d.Util.merge(options, {
          scene: {
            center: { lat: 20.217716, lng: 82.229053, alt: 38911656, heading: 10, pitch: -90 },
          },
          cameraController: {
            maximumZoomDistance: 9000000000,
            constrainedAxis: false, //解除在南北极区域鼠标操作限制
          },
        });

        //创建三维地球场景
        map = new mars3d.Map("mars3dContainer", mapOptions);

        //移除2.5D视图
        var arr = $(".cesium-sceneModePicker-wrapper").children();
        if (arr.length > 3) {
          arr[3].remove();
        }

        //创建矢量数据图层
        var graphicLayer = new mars3d.layer.GraphicLayer();
        map.addLayer(graphicLayer);

        //滑动条需要先设置，后才能取值
        $("#model_heading")
          .slider({ min: 0, max: 360, step: 1, value: 0 })
          .on("change", (e) => {
            if (e && e.value) {
              $("#model_heading_2").val(e.value.newValue);

              modelGraphic.heading = e.value.newValue;
              satelliteSensor.heading = e.value.newValue;
            }
          });
        $("#model_heading_2").change(function () {
          var value = Number($(this).val());
          $("#model_heading").slider("setValue", value);

          modelGraphic.heading = value;
          satelliteSensor.heading = value;
        });

        $("#model_pitch")
          .slider({ min: -180, max: 180, step: 1, value: 0 })
          .on("change", (e) => {
            if (e && e.value) {
              $("#model_pitch_2").val(e.value.newValue);

              modelGraphic.pitch = e.value.newValue;
              satelliteSensor.pitch = e.value.newValue;
            }
          });
        $("#model_pitch_2").change(function () {
          var value = Number($(this).val());
          $("#model_pitch").slider("setValue", value);

          modelGraphic.pitch = value;
          satelliteSensor.pitch = value;
        });

        $("#model_roll")
          .slider({ min: -180, max: 180, step: 1, value: 0 })
          .on("change", (e) => {
            if (e && e.value) {
              $("#model_roll_2").val(e.value.newValue);

              modelGraphic.roll = e.value.newValue;
              satelliteSensor.roll = e.value.newValue;
            }
          });
        $("#model_roll_2").change(function () {
          var value = Number($(this).val());
          $("#model_roll").slider("setValue", value);

          modelGraphic.roll = value;
          satelliteSensor.roll = value;
        });

        $("#model_angle1")
          .slider({ min: 0, max: 89, step: 0.001, value: 5 })
          .on("change", (e) => {
            if (e && e.value) {
              $("#model_angle1_2").val(e.value.newValue);
              satelliteSensor.angle1 = e.value.newValue;
            }
          });
        $("#model_angle1_2").change(function () {
          var value = Number($(this).val());
          $("#model_angle1").slider("setValue", value);
          satelliteSensor.angle1 = value;
        });

        $("#model_angle2")
          .slider({ min: 0, max: 89, step: 0.001, value: 10 })
          .on("change", (e) => {
            if (e && e.value) {
              $("#model_angle2_2").val(e.value.newValue);
              satelliteSensor.angle2 = e.value.newValue;
            }
          });
        $("#model_angle2_2").change(function () {
          var value = Number($(this).val());
          $("#model_angle2").slider("setValue", value);
          satelliteSensor.angle2 = value;
        });

        //测试位置
        $("#model_x").val(117.169969);
        $("#model_y").val(31.840886);
        $("#model_z").val(9980000);

        //参数
        var x = Number($("#model_x").val());
        var y = Number($("#model_y").val());
        var z = Number($("#model_z").val());

        var heading = Number($("#model_heading").val());
        var pitch = Number($("#model_pitch").val());
        var roll = Number($("#model_roll").val());

        var angle1 = Number($("#model_angle1").val()); //半张角
        var angle2 = Number($("#model_angle2").val()); //半张角

        var position = Cesium.Cartesian3.fromDegrees(x, y, z);

        //加个模型
        modelGraphic = new mars3d.graphic.ModelEntity({
          name: "卫星模型",
          position: position,
          style: {
            url: "//data.mars3d.cn/gltf/mars/weixin.gltf",
            scale: 1,
            minimumPixelSize: 150,
            heading: heading,
            pitch: pitch,
            roll: roll,
          },
        });
        graphicLayer.addGraphic(modelGraphic);

        //打开3个轴进行显示对比
        modelGraphic.debugAxis = true;

        //视锥体
        satelliteSensor = new mars3d.graphic.SatelliteSensor({
          position: position,
          style: {
            sensorType: mars3d.graphic.SatelliteSensor.Type.Rect,
            angle1: angle1,
            angle2: angle2,
            heading: heading,
            pitch: pitch,
            roll: roll,
            color: "rgba(0,255,255,0.7)",
          },
          fixedFrameTransform: converter,
          reverse: reverse,
        });
        graphicLayer.addGraphic(satelliteSensor);

        $("#chkShowModelMatrix").change(function () {
          var val = $(this).is(":checked");
          modelGraphic.debugAxis = val;
        });
        $("#modelMatrixLength").change(function () {
          var value = Number($(this).val());
          modelGraphic.debugAxisLength = value * 1000;
        });

        $("#chkShowCone").change(function () {
          var val = $(this).is(":checked");
          satelliteSensor.show = val;

          if (val) {
            $(".coneEntityAttr").show();
          } else {
            $(".coneEntityAttr").hide();
          }
        });

        $("#chkUnderground").click(function () {
          satelliteSensor.rayEllipsoid = $(this)[0].checked;
        });

        $("#model_x").change(function () {
          updatePosition();
        });

        $("#model_y").change(function () {
          updatePosition();
        });

        $("#model_z").change(function () {
          updatePosition();
        });

        $("input[type=radio][name=shadingMaterials]").change(function () {
          if (this.value === "1") {
            satelliteSensor.sensorType = mars3d.graphic.SatelliteSensor.Type.Conic;
            $("#tr_angle2").hide();
          } else {
            satelliteSensor.sensorType = mars3d.graphic.SatelliteSensor.Type.Rect;
            $("#tr_angle2").show();
          }
        });

        $("#btnGetRegion").click(function () {
          map.graphicLayer.clear();

          var coords = satelliteSensor.getAreaCoords(); //导出成像区边界坐标
          if (!coords || coords.length == 0) {
            haoutil.alert("当前与地球无成像区边");
            return;
          }

          //显示边界点，测试
          map.graphicLayer.clear();
          $(coords).each(function (i, item) {
            var primitive = new mars3d.graphic.PointPrimitive({
              position: item,
              style: {
                color: "#ff0000",
                pixelSize: 8,
                outline: true,
                outlineColor: "#ffffff",
                outlineWidth: 2,
                clampToGround: true,
              },
            });
            map.graphicLayer.addGraphic(primitive);
          });

          //提示边界值，测试
          haoutil.alert(JSON.stringify(coords));
        });
        $("#btnRemoveAll").click(function () {
          map.graphicLayer.clear();
        });

        $("#btnGetCenter").click(function () {
          map.graphicLayer.clear();

          var groundPosition = satelliteSensor.groundPosition;
          if (!groundPosition) {
            haoutil.alert("当前与地球无交点");
            return;
          }

          var primitive = new mars3d.graphic.PointPrimitive({
            position: groundPosition,
            style: {
              color: "#ff0000",
              pixelSize: 8,
              outline: true,
              outlineColor: "#ffffff",
              outlineWidth: 2,
              clampToGround: true,
            },
          });
          map.graphicLayer.addGraphic(primitive);

          var point = mars3d.LatLngPoint.fromCartesian(groundPosition);
          haoutil.alert(point.toString());
        });
      }

      function updatePosition() {
        var x = Number($("#model_x").val());
        var y = Number($("#model_y").val());
        var z = Number($("#model_z").val());
        var position = Cesium.Cartesian3.fromDegrees(x, y, z);

        modelGraphic.position = position;
        satelliteSensor.position = position;
      }

      function locate() {
        map.flyToGraphic(modelGraphic, { radius: modelGraphic.height * 2 });
      }
    </script>
  </body>
</html>
